package com.example.xianji.adapter;

import java.util.ArrayList;

import com.example.xianji.activity.Main_My_XuQiu_DetailsActivity;
import com.example.xianji.R;
import com.example.xianji.bean.Service;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class My_XuQiu_Adapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<Service> list;


    public My_XuQiu_Adapter(Context mContext, ArrayList<Service> list) {
        super();
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder mHolder;
        if (convertView == null) {
            mHolder = new Holder();
            convertView = View.inflate(mContext, R.layout.my_xuqiu_listview_item, null);
            mHolder.my_xuqiu_title = (TextView) convertView.findViewById(R.id.my_xuqiu_title);
            mHolder.my_xuqiu_time = (TextView) convertView.findViewById(R.id.my_xuqiu_time);
            mHolder.my_xuqiu_status = (TextView) convertView.findViewById(R.id.my_xuqiu_status);
            convertView.setTag(mHolder);
        }
        mHolder = (Holder) convertView.getTag();

        mHolder.my_xuqiu_title.setText(list.get(position).getTitle());
        mHolder.my_xuqiu_time.setText(list.get(position).getCreated_at());
        if (list.get(position).getStatus() == 1 || list.get(position).getStatus() == 16 || list.get(position).getStatus() == 17 || list.get(position).getStatus() == 12) {
            mHolder.my_xuqiu_status.setText("已发布");
        } else if (list.get(position).getStatus() == 11) {
            mHolder.my_xuqiu_status.setText("待审核");
        } else if (list.get(position).getStatus() == 10) {
            mHolder.my_xuqiu_status.setText("审核不通过");
        } else if (list.get(position).getStatus() == 13 || list.get(position).getStatus() == 14) {
            mHolder.my_xuqiu_status.setText("专家对接中");
        }
        final int a = position;
        convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, Main_My_XuQiu_DetailsActivity.class);
                intent.putExtra("my_xuqiu_detail_id", list.get(a).getId());
                mContext.startActivity(intent);
            }
        });
        return convertView;
    }

    class Holder {
        TextView my_xuqiu_title;
        TextView my_xuqiu_time;
        TextView my_xuqiu_status;
    }
}
